#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e9 + 1;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
       for(int i=2;i<=n/i;i++)
       {
            if(n%i==0)
            {
                int cnt=0;
                while(n%i==0)
                {
                    cnt++;
                    n/=i;
                }
                cout<<i<<" "<<cnt<<endl;
            }
       }
       if(n>1) cout<<n<<" "<<1<<endl;
       cout<<endl;
    }
    return 0;
}